using B.S.XZYData.Api.Wrter.Application.Command.ProductionStatistics;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System.Net.Mime;

namespace B.S.XZYData.Api.Wrter.Controllers
{
    /// <summary>
    /// 产量统计写入接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ProductionStatisticsController : ControllerBase
    {
        private readonly IMediator _mediator;
        
        public ProductionStatisticsController(IMediator mediator) 
        { 
            _mediator = mediator; 
        }

        /// <summary>
        /// 导出产量统计
        /// </summary>
        [HttpGet]
        public async Task<FileContentResult> Export([FromQuery] ExportProductionStatisticsCommand query)
        {
            var result = await _mediator.Send(query);
            if (result.Code == ApiEnum.Success)
            {
                return File(result.Data, MediaTypeNames.Application.Octet, "产量统计导出.xlsx");
            }
            else
            {
                throw new System.Exception(result.Msg);
            }
        }
    }
} 